<!--智慧消防V1.0-info页面-->
<template>
    <div class="app-container" ref="content">
        <div style="text-align: center;padding: 10px">{{noticeInfo.name}}-详情信息</div>
        <el-row :gutter="10">

                <el-form v-model="noticeInfo" ref="alarmInfo" label-width="120px">
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                        <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                            <el-form-item label="所属主体" prop="enterpriseName">
                                {{ noticeInfo.enterpriseName }}
                            </el-form-item>
                        </el-col>
                    <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                        <el-form-item label="通知名称" prop="name">
                            {{noticeInfo.name}}
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                        <el-form-item label="通知内容"  prop="content">
                            {{noticeInfo.content}}
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                        <el-form-item label="通知类型 " prop="type">
                            {{noticeInfo.type | noticeType}}
                        </el-form-item>
                    </el-col>
                      <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                        <el-form-item label="通知时间 " prop="noticeTime">
                          {{noticeInfo.noticeTime | dateFormat}}
                        </el-form-item>
                      </el-col>
                    </el-col>
                </el-form>
            <uc-table url="admin/notice/getInNoticeInfoPage" name="我的通知" ref="noticeTable" pageable table-border :search-form="searchForm">
                <template slot="searchForm">
                    <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
                        <!--搜索输入框-->
                        <el-form-item  prop="feedbackStatus">
                            <el-select v-model="searchForm.feedbackStatus" placeholder="请选择反馈状态" style="width: 100%">
                                <el-option :value="4" label="全部" ></el-option>
                                <el-option :value="0" label="未反馈" ></el-option>
                                <el-option :value="1" label="已反馈" ></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
                        </el-form-item>
                    </el-form>
                </template>
                <template slot="columns">
                    <el-table-column prop="enterpriseName" label="所属主体" align="left" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="noticeName" label="通知名称" align="left" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="noticeType" label="通知类型" align="left">
                        <template slot-scope="scope">
                            {{scope.row.type| noticeType}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="receiverName" label="接收人" align="left"></el-table-column>
                    <el-table-column prop="noticeContent" label="通知内容" align="left" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="feedbackContent" label="反馈内容" align="left" :show-overflow-tooltip="true"></el-table-column>
                    <el-table-column prop="feedbackStatus" label="反馈状态" align="left">
                        <template slot-scope="scope">
                            {{scope.row.feedbackStatus | noticeFeedback }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="readTime" label="读取时间" align="left">
                        <template slot-scope="scope">
                            {{scope.row.readTime | readTimeFormat }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
                        <template slot-scope="scope">
                            <!--编辑按钮-->
<!--                            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">反馈</el-button>-->
                            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading" @click="handleDelete(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </uc-table>
            <el-dialog title="通知反馈" :visible.sync="hidden">
                <div class="form" >
                    <el-form :model="feedbackForm" ref="feedbackForm" label-width="100px" :rules="feedbackFormRules">
                        <el-form-item label="反馈内容" prop="feedbackContent">
                            <el-input v-model="feedbackForm.feedbackContent" placeholder="请输入反馈内容" clearable></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" style="text-align: center" class="dialog-footer">
                        <el-button type="primary" @click="SubmitText">反馈
                        </el-button>
                    </div>
                </div>
            </el-dialog>
        </el-row>
    </div>
</template>

<script>
import {deleteInNoticeInfo,removeInNoticeInfo, getInNoticeVo, updateMyNoticeFeedback} from "@/api/notice";
import UcTable from "@/components/UcTable/index.vue";
export default {
    name: "info",
    components: {UcTable},
    data(){
        return{
            noticeInfo:{

            },
            searchForm:{
                deleted:false,
                noticeId:this.$route.params.ucId
            },
            hidden:false,
            feedbackForm:{
                ucId:'',
            },
            feedbackFormRules:{
                feedbackContent: [{required: true, message: '反馈内容不能为空', trigger: 'blur'}],
            },
            deleteLoading:false,

        }
    },
    created() {
        this.$nextTick(() => {
            this.getInNoticeVo(this.$route.params.ucId)
        });
    },
    methods:{
        handleSearch(){
            this.$refs.noticeTable.getTableData(1)
        },
        handleEdit(val){

            this.hidden=true
            this.feedbackForm ={}
            this.$nextTick(()=>{
                this.$refs['feedbackForm'].clearValidate();
            })
            this.feedbackForm.ucId=val.ucId
        },
        SubmitText(){
            this.$refs['feedbackForm'].validate(valid => {
                if (valid) {
                    updateMyNoticeFeedback(this.feedbackForm).then(res => {
                        this.$notify.success({
                            title: '成功',
                            message: "反馈成功"
                        })
                        this.hidden=false
                        this.handleSearch()
                    }).catch(res => {
                        this.$notify.error({
                            title: '反馈失败',
                            message: res.msg
                        })
                    })
                } else {
                    console.log("表单验证不通过")
                }
            })

        },
        handleDelete(val){
            this.$confirm('您确定要执行删除'+val.noticeName+'这个通知信息吗？', '提醒信息', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.deleteLoading = true
                    removeInNoticeInfo(val).then(res=>{
                    this.deleteLoading = false
                    this.$notify.success({
                        title: '成功',
                        message: "删除通知信息成功"
                    })
                    this.handleSearch()
                }).catch(res=>{
                    this.deleteLoading = false
                    this.$notify.error({
                        title: '失败',
                        message: res.msg
                    })
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        getInNoticeVo(val){
            //获取企业信息数据
            let loadingInstance = this.$loading({
                target:this.$refs.content,
                text:'数据加载中'
            });
            getInNoticeVo({ucId:val}).then(res=>{
                console.log(res)
                this.noticeInfo = res.data
                loadingInstance.close()
                this.$notify.success({
                    title: '成功',
                    message: "获取通知信息成功"
                })
            }).catch(error=>{
                console.log(error)
                loadingInstance.close()
                this.$notify.error({
                    title: '失败',
                    message: "获取通知信息失败"
                })
            })
        }
    }
}
</script>

